/*
 * Danny Wu 2/9/2014
 */

package post2;

/**
 * Manager will set up store, set up post, and set up catalog
 */
public class Manager {
    //the store the manager will initialize
    Store store;
    //the product catalog the manager will initialize
    ProductCatalog catalog;
    
    /**
     * constructer of manager. will create the product catalog
     * @param newStore the store the manager will initialize
     * @param reader the product reader the manager will set up the product catalog with
     */
    public Manager(Store newStore, ProductReader reader){
        this.store=newStore;
        this.initCatalog(reader);
    }
    
    /**
     * initialize the store, post, product catalog
     */
    public void open(){
        this.store.initCatalog(this.catalog);
        this.store.initStock();
        this.store.initPost();
    }
    
    /**
     * creates a ProductCatalog using the productReader given
     * @param reader the productReader that will reader all the product from file
     */
    private void initCatalog(ProductReader reader){
        this.catalog=new ProductCatalog();
        ProductSpec itemSpec;
        while(reader.hasMoreProducts()){
            itemSpec=reader.getNextProduct();
            this.catalog.addToProductCatalog(itemSpec.getUPC(), itemSpec);
        }
    }
    
    /*
     public static void main(String[] args) {
         Manager manager=new Manager(new Store("Store"), new ProductReader("products.txt"));
         ProductCatalog spec=manager.catalog;
         Enumeration e=spec.getAllUPC();
         while(e.hasMoreElements()){
             System.out.println(e.nextElement().toString());
         }
         
     }
    */
}
